package com.neo.web.controller.pub;

import com.neo.common.annotation.Log;
import com.neo.common.core.controller.BaseController;
import com.neo.common.core.domain.AjaxResult;
import com.neo.common.core.page.TableDataInfo;
import com.neo.common.enums.BusinessType;
import com.neo.common.utils.poi.ExcelUtil;
import com.neo.pub.domain.Patient;
import com.neo.pub.service.IPatientService;
import com.neo.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 用户信息
 * 
 * @author tr
 */
@Controller
@RequestMapping("/pub/pca")
public class PatientController extends BaseController
{
    private String prefix = "pub/pca";

    @Autowired
    private IPatientService iPatientService;


//    @RequiresPermissions("system:user:view")
    @GetMapping()
    public String patient()
    {
        return prefix + "/patient";
    }

//    @RequiresPermissions("system:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Patient patient)
    {
        startPage();
        List<Patient> list = iPatientService.selectPatientList(patient);
        return getDataTable(list);
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{patientId}")
    public String edit(@PathVariable("patientId") String patientId, ModelMap mmap)
    {
        mmap.put("patient", iPatientService.selectPatientById(patientId));
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @Log(title = "病人管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated Patient patient )
    {
        return toAjax(iPatientService.updatePatient(patient));
    }


    @Log(title = "病人清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Patient patient)
    {
        List<Patient> list = iPatientService.selectPatientList(patient);
        ExcelUtil<Patient> util = new ExcelUtil<>(Patient.class);
        return util.exportExcel(list, "用户数据");
    }
}